package com.encryption.feature.doc.ui.render
{
	import com.encryption.controls.confirm.ConfirmPopUpManager;
	import com.encryption.controls.tip.TipShowManager;
	import com.encryption.feature.doc.FileLogManager;
	import com.encryption.framework.constant.FileActionConstant;
	import com.encryption.rpc.RPCEvent;
	import com.encryption.rpc.facade.FileFacade;
	import com.encryption.rpc.facade.RPCFacadeHelper;
	import com.encryption.rpc.model.File;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.DataGrid;
	import mx.core.UIComponent;
	import mx.rpc.events.ResultEvent;

	public class DeleteOperationLabel extends OperationLabel
	{
		public function DeleteOperationLabel()
		{
			super();
			
			text = "删除";
		}
		
		override protected function get field():String
		{
			return "canDelete";
		}
		
		override protected function mouseClickHandle(event:MouseEvent):void
		{
			ConfirmPopUpManager.centerPopUp(ensureToDelete);
		}
		
		private function ensureToDelete():void
		{
			new FileFacade(FileFacade.OPERATION_DETETE_FILE, {arg0:File(target).id}, deleteFileHandle);
		}
		
		private function deleteFileHandle(event:RPCEvent):void
		{
			RPCFacadeHelper.rpcHandle(event, deleteHandle, "删除失败");
		}
		
		private function deleteHandle(resultEvent:ResultEvent):void
		{
			var parentObj:DisplayObjectContainer = owner;
			while(!(parentObj is DataGrid)){
				parentObj = parentObj.parent;
			}
			
			FileLogManager.instance.addLog(File(target).id, FileActionConstant.ACTION_DELETE);
			parentObj.dispatchEvent(new Event("fileListChange"));
			TipShowManager.showMessageTip("删除成功");
		}
		
	}
}